import Vue from 'vue'
import App from './App.vue'
import Vuex from 'vuex'

Vue.config.productionTip = false
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 1,
    list: [2, 1, 3, 4, 5, 6, 8]
  },
  mutations: {
    addCount (state, payload) {
      state.count += payload
    }
  },
  actions: {
    asyncAddCount (context, payload) {
      setTimeout(() => {
        context.commit('addCount', payload)
      }, 1000)
    }
  },
  getters: {
    // filterList: () => {}
    filterList (state) {
      return state.list.filter(item => item % 2 === 0)
    },
    idFast (state) {
      return state.user.id
    }
  },
  modules: {
    user: {
      namespaced: true,
      state: {
        id: 888
      },
      mutations: {
        updateId (state) {
          state.id = 111111
        }
      }
    },
    profile: {
      state: {
        address: '济南'
      }
    },
    setting: {
      state: {
        img: '一个地址'
      }
    }
  }
})

new Vue({
  render: h => h(App),
  store
}).$mount('#app')
